import 'package:flutter/material.dart';
import 'package:home_box/pages/medicine/MedicineV/home_medicine.dart';
import 'package:home_box/pages/mine/home_mine.dart';
import 'package:home_box/pages/wrongRecorde/home_wrong_recode.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  Widget build(BuildContext context) {
    return Home();
  }

  @override
  State<StatefulWidget> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  double size = 15;
  int currentIndex = 0;
  static const List<Widget> _bottomBarContent = <Widget>[
    HomeMedicine(),
    HomeWrongRecode(),
    HomeMine(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      ///使用SafeArea规避内容延伸到状态栏
      body: SafeArea(child: _bottomBarContent[currentIndex]),
      bottomNavigationBar: SizedBox(
        height: 40,
        child: BottomNavigationBar(
          items: _bottoms(),
          selectedItemColor: Color(0xFF1295D9),
          currentIndex: currentIndex,
          onTap: _bottomTap,
        ),
      ),
    );
  }

  /// 底部点击事件
  void _bottomTap(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  _bottoms() {
    return [
      bottomBarItem(
        'images/home_medicine_normal.png',
        'images/home_medicine_selected.png',
        '药箱',
      ),
      bottomBarItem(
        'images/home_wrong_record_normal.png',
        'images/home_wrong_record_selected.png',
        '错题本',
      ),
      bottomBarItem(
        'images/home_mine_normal.png',
        'images/home_mine_selected.png',
        '我的',
      ),
    ];
  }

  ///底部Tab
  BottomNavigationBarItem bottomBarItem(String icon,
      String activeIcon,
      String text,) {
    return BottomNavigationBarItem(
      icon: SizedBox(
        width: size,
        height: size,
        child: Image(image: AssetImage(icon)),
      ),
      activeIcon: SizedBox(
        width: size,
        height: size,
        child: Image(image: AssetImage(activeIcon)),
      ),
      label: text,
    );
  }
}
